#ifndef _CHALLENGEIMPL_HXX_
#define _CHALLENGEIMPL_HXX_

#include <openssl/blowfish.h>
#include "mytypes.h"
#include "constants.h"

typedef struct
{
  tUInt32 data_len;
  tByte data[CHALLENGELENGTH];
  tUInt32 signature_len;
  tByte signature[MAXCHALLENGESIGNATURELEN];
} tChallenge;

class Challenge;
class ChallengeImpl
{
public:
  ChallengeImpl(const tByte *remote_public_key, tUInt32 remote_public_key_len, const tByte *private_key, tUInt32 private_key_len,const tByte *challenge_key, tUInt32 challenge_key_len);
  ~ChallengeImpl();

  bool Generate();
  bool IsEqual(const ChallengeImpl &challenge) const;
  bool Resolve();
  bool Sign();
  bool Verify();
  
  const tByte *Content() const;
  tByte *Content();
  
private:
  void Clear();
  bool Instanciate();
  void Encrypt() const;
  void Decrypt() const;

  mutable tChallenge *_data;

  const tByte *_remote_public_key;
  tUInt32 _remote_public_key_len;
  const tByte *_private_key;
  tUInt32 _private_key_len;

  BF_KEY *_key;
  tByte *_ivec;

};

#endif /* _CHALLENGEIMPL_HXX_ */
